package cn.itcast.filter;

import org.apache.shiro.subject.Subject;
import org.apache.shiro.web.filter.authz.AuthorizationFilter;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

public class MyPermsFilter extends AuthorizationFilter {
    public MyPermsFilter() {
    }

    @Override
    protected boolean isAccessAllowed(ServletRequest request, ServletResponse response, Object mappedValue) throws Exception {
       ///system/dept/list.do = perms["部门管理","删除部门"]
        Subject subject = this.getSubject(request, response);
        String[] perms=(String[]) ((String[])mappedValue);
        if (perms!=null &&perms.length>0){
            for (String perm : perms) {
                if (subject.isPermitted(perm)){
                    return true;
                }
            }
            return false;
        }
        return true;
    }
}
